#!/bin/sh
# ^ Note that we use sh, not bash, for alpine compatibility
set -e

# Exclude ourselves from PATH, find the real node, then reset PATH
PATH="$(printf '%s\n' "$PATH" | sed "s:$(dirname "$0")\:::g")"
    # ^ This is made more complicated by sh, since we can't use variable expansion, but this
    # should be equivalent. We use : as a safe sed delim here, though it is confusing!

real_node=`command -v node`
PATH="`dirname "$0"`:$PATH"

PREPEND_PATH=`dirname "$0"`/../js/prepend-node.js

# Call node with the given arguments, prefixed with our extra logic
if command -v winpty >/dev/null 2>&1; then
    winpty "$real_node" -r "$PREPEND_PATH" "$@"
else
    "$real_node" -r "$PREPEND_PATH" "$@"
fi